﻿Imports System.Collections.Generic
Imports System.ComponentModel
Imports MySql.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Threading

Public Class frmMain

    Dim logoff As Boolean
    Public Delegate Sub frm(ByVal formulario As Form)
    Public teste As New frm(AddressOf Abrir_Form)

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Me.Text = "S.C.E - Sistema de Cadastro Escolar ( Usuário: " + frmLogin.nome & " )"
        'Me.Opacity = 0
        'Dim cont As Double = 0
        'While cont <= 1
        'Me.Opacity = cont
        'Me.Refresh()
        'Thread.Sleep(15)
        'cont += 0.1
        'End While
        'Animacao(Me)
        If frmLogin.acesso = 1 Then
            miCadUsuario.Enabled = True
            miEditarUsuarios.Enabled = True
            miCadUsuario.Visible = True
            miEditarUsuarios.Visible = True
        Else
            miCadUsuario.Enabled = False
            miEditarUsuarios.Enabled = False
            miCadUsuario.Visible = False
            miEditarUsuarios.Visible = False
        End If

    End Sub

    Private Sub miCadAluno_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miCadAluno.Click
        Abrir_Form(New frmCadAluno())
    End Sub

    Private Sub miPesqAluno_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miPesqAluno.Click
        Abrir_Form(New frmPesqAluno())
    End Sub

    Private Sub miCadProfessor_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miCadProfessor.Click
        Abrir_Form(New frmCadProfessor())
    End Sub

    Private Sub miPesqProfessor_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miPesqProfessor.Click
        Abrir_Form(New frmPesqProfessor())
    End Sub

    Private Sub miLogoff_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miLogoff.Click
        Me.Hide()
        Dim login As New frmLogin()
        login.Show()
        logoff = True
        Me.Close()
    End Sub

    Private Sub miCadUsuario_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miCadUsuario.Click
        Abrir_Form(New frmCadUsuario())
    End Sub

    Private Sub miEditarUsuario_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miEditarUsuarios.Click
        Abrir_Form(New frmEditarUsuario())
    End Sub

    Private Sub miTrocarSenha_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miTrocarSenha.Click
        Abrir_Form(New frmTrocarSenha())
    End Sub

    Private Sub miCadNotaAluno_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miCadNotaAluno.Click
        Abrir_Form(New frmCadNotaAluno())
    End Sub

    Private Sub miSair_Click(ByVal sender As Object, ByVal e As EventArgs) Handles miSair.Click
        End
    End Sub

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles MyBase.FormClosing
        If logoff = False Then
            End
        End If
    End Sub

    ' Função para abrir os Forms Filhos hahahahah NINJA POG MASTER :)
    Public Sub Abrir_Form(ByVal form As Form)
        For Each formFilho As Form In Me.MdiChildren
            If formFilho.GetType.ToString() = form.GetType.ToString() Then
                formFilho.WindowState = FormWindowState.Normal
                Return
            End If
        Next
        form.MdiParent = Me
        form.Show()
    End Sub

End Class
